import { 
  createStore,
  // applyMiddleware, 
  compose, 
  combineReducers 
} from 'redux';

// import thunk from 'redux-thunk'
import counterReducer from './counter';
import homeReducer from './home';
//导入手写中间件
import { log, thunk, applyMiddleware } from '../middleware'

//将两个reducer合并在一起
const reducer = combineReducers({
  counter: counterReducer,
  home: homeReducer
})

//redux-devtools
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({trace: true}) || compose;

//使用官方 redux-thunk 中间件
// const store = createStore(reducer, composeEnhancers(applyMiddleware(thunk)));

//使用手写的redux-thunk中间件
const store = createStore(reducer);

//应用手写的 redux 中间件
applyMiddleware(store, log, thunk);

export default store
